package org.gitman.agentplatform.ui.simulation;

import java.awt.event.MouseEvent;

import javax.swing.JTable;

import org.gitman.agentplatform.agent.api.InternalAgentInfo;
import org.gitman.agentplatform.core.PlatformManager;

public class AgentTable extends JTable {
	private AgentTableModel model;
	public AgentTable(AgentTableModel model) {
		super(model);
		this.model = model;
	}
	
	@Override
	public String getToolTipText(MouseEvent event) {
		int row = rowAtPoint(event.getPoint());
		Integer id = (Integer) model.getValueAt(row, 0);
		InternalAgentInfo info = PlatformManager.getInstatnce().getSimulation().getAgentManager().getAgentInfo(id);
		StringBuilder infoBuilder = new StringBuilder("<html>");
		
		infoBuilder.append("<center><b>AGENT INFO</b></center>");
		infoBuilder.append("<table border=\"0\">");
		infoBuilder.append(createRow("ID", info.getId().toString()));
		infoBuilder.append(createRow("start", info.getStartVertexID().toString()));
		infoBuilder.append(createRow("end", info.getEndVertexID().toString()));
		infoBuilder.append(createRow("state", info.getAgentState().toString()));
		infoBuilder.append(createRow("observablity", info.getObservString()));
		infoBuilder.append(createRow("predictablity", info.getPredictString()));
		infoBuilder.append(createRow("relieability", info.getRelieString()));
		infoBuilder.append(createRow("plan", (info.getAgentPlan() == null || info.getCurrentVertexID() == null)? "-" : info.getAgentPlan().getHtml(info.getCurrentVertexID())));
		infoBuilder.append("</table>");
		
		infoBuilder.append("</html>");
		return  infoBuilder.toString();
	}

	private String createRow( String key, String val) {		
		return "<tr><td>" + key + "</td><td>" + val + "</td></tr>";
	}

}
